package com.lebron.kotlin.utils

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import com.lebron.kotlin.R

/**
 * 意图跳转
 */
object IntentUtils {

    /**
     * 跳转设置系统应用权限界面
     *
     */
    fun intentSetting(context: Context){
        context.startActivity(Intent(Settings.ACTION_SETTINGS))
    }
    /**
     * 跳转到当前应用权限设置界面
     */
    fun intentAppSetting(context: Context){
        val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        intent.data = Uri.fromParts("package",context.packageName,null)
        context.startActivity(intent)
    }

    /**
     * 分享
     *
     * @param context
     * @param content 分享内容
     * @param uri     分享图片uri
     */
    fun share(context: Context, content: String, uri: Uri?) {
        val shareIntent = Intent()
        shareIntent.action = Intent.ACTION_SEND
        if (uri != null) {
            shareIntent.putExtra(Intent.EXTRA_STREAM, uri)
            shareIntent.type = "image/*"
            //当用户选择短信时使用sms_body取得文字
            shareIntent.putExtra("sms_body", content)
        } else {
            shareIntent.type = "text/plain"
        }
        shareIntent.putExtra(Intent.EXTRA_TEXT, content)
        context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string.string_share)))
    }
}